package main

import (
	"fmt"
	"io"
	"strings"
)

func main() {
	// data, _ := ReadFrom(strings.NewReader("yuekinger"), 9)
	// data, err := ReadFrom(strings.NewReader("yuekinger"), 9)

	// data, _ := ReadFrom(os.Stdin, 7)
	// fmt.Printf("data: %v len:%d %d\n", string(data), len(data), n)
	reader := strings.NewReader("yuekinger")
	data := make([]byte, 4)
	n, err := reader.ReadAt(data, 3)
	// n, err = reader.ReadAt(data, 1)
	if err != nil {
		fmt.Println(err)
		// panic("error")
	}
	fmt.Printf("%s, %d", data, n)
}

func ReadFrom(reader io.Reader, num int) ([]byte, error) {
	data := make([]byte, num)
	_, err := reader.Read(data)
	if err != nil {
		return nil, err
	}
	return data, nil
}
